load("//bazel:compat.bzl", "ANDROID_ONLY", "SKIP_ON_WINDOWS")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@fmeum_rules_jni//jni:defs.bzl", "java_jni_library")

java_import(
    name = "jazzer_bootstrap_android_import",
    jars = [
        "//src/main/java/com/code_intelligence/jazzer/runtime:jazzer_bootstrap",
    ],
    tags = ["manual"],
    target_compatible_with = ANDROID_ONLY,
)

android_library(
    name = "jazzer_bootstrap_android_lib",
    tags = ["manual"],
    target_compatible_with = ANDROID_ONLY,
    visibility = [
        "//src/main/java/com/code_intelligence/jazzer/agent:__pkg__",
    ],
    exports = [
        ":jazzer_bootstrap_android_import",
    ],
)

android_binary(
    name = "jazzer_bootstrap_android_bin",
    manifest = "//launcher/android:android_manifest",
    min_sdk_version = 26,
    tags = ["manual"],
    target_compatible_with = ANDROID_ONLY,
    deps = [
        ":jazzer_bootstrap_android_lib",
    ],
)

copy_file(
    name = "jazzer_bootstrap_android",
    src = "jazzer_bootstrap_android_bin.apk",
    out = "jazzer_bootstrap_android.jar",
    tags = ["manual"],
    target_compatible_with = ANDROID_ONLY,
    visibility = [
        "//src/main/java/com/code_intelligence/jazzer/agent:__pkg__",
    ],
)

java_jni_library(
    name = "dex_file_manager",
    srcs = ["DexFileManager.java"],
    native_libs = [
        "//src/main/native/com/code_intelligence/jazzer/android:android_native_agent",
    ],
    tags = ["manual"],
    target_compatible_with = ANDROID_ONLY,
)

android_library(
    name = "jazzer_standalone_library",
    tags = ["manual"],
    target_compatible_with = ANDROID_ONLY,
    exports = [
        "//deploy:jazzer-api-lib",
        "//src/main/java/com/code_intelligence/jazzer:jazzer_import",
    ],
)

android_binary(
    name = "jazzer_standalone_android",
    manifest = "//launcher/android:android_manifest",
    min_sdk_version = 26,
    tags = ["manual"],
    target_compatible_with = ANDROID_ONLY,
    visibility = [
        "//:__pkg__",
        "//launcher/android:__pkg__",
    ],
    deps = [
        ":dex_file_manager",
        ":jazzer_standalone_library",
    ],
)

java_jni_library(
    name = "android_runtime",
    srcs = ["AndroidRuntime.java"],
    native_libs = select({
        "@platforms//os:android": [
            "//src/main/native/com/code_intelligence/jazzer/driver:jazzer_android_tooling",
        ],
        "//conditions:default": [],
    }),
    tags = ["manual"],
    visibility = [
        "//src/main/java/com/code_intelligence/jazzer:__pkg__",
        "//src/main/java/com/code_intelligence/jazzer/driver:__subpackages__",
        "//src/main/native/com/code_intelligence/jazzer/driver:__subpackages__",
    ],
    deps = [
        "//src/main/java/com/code_intelligence/jazzer/driver:opt",
        "//src/main/java/com/code_intelligence/jazzer/runtime:constants",
        "//src/main/java/com/code_intelligence/jazzer/utils:log",
    ],
)
